package groups.common.gui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import javax.swing.WindowConstants;
import org.jdesktop.application.Application;
import javax.swing.SwingUtilities;
import java.sql.Connection;
import javax.swing.JButton;
import groups.common.dao.IUserDao;
import groups.common.dao.JDBCUserDao;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class UserDelete extends javax.swing.JFrame {
	private JPanel topPanelCenter;
	private Connection con;
	private JTextField idDelete;
	private JButton cancel;
	private JButton confirm;
	private JTextPane deleteText;

	/**
	* Auto-generated main method to display this JFrame
	*/
		
	public UserDelete(Connection con) {
		super();
		this.con=con;
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				topPanelCenter = new JPanel();
				getContentPane().add(topPanelCenter, BorderLayout.CENTER);
				topPanelCenter.setPreferredSize(new java.awt.Dimension(308, 270));
				{
					deleteText = new JTextPane();
					topPanelCenter.add(deleteText);
					deleteText.setName("deleteText");
				}
				{
					idDelete = new JTextField();
					topPanelCenter.add(idDelete);
					idDelete.setPreferredSize(new java.awt.Dimension(188, 22));
				}
				{
					confirm = new JButton();
					topPanelCenter.add(confirm);
					confirm.setName("confirm");
					confirm.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("confirm.actionPerformed, event="+evt);
							actionConfirm();
						}
					});
				}
				{
					cancel = new JButton();
					topPanelCenter.add(cancel);
					cancel.setName("cancel");
					cancel.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("cancel.actionPerformed, event="+evt);
							dispose();
						}
					});
				}
			}
			pack();
			this.setSize(245, 121);
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(getContentPane());
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private void actionConfirm(){
		IUserDao user = new JDBCUserDao(con);
		user.delete(Integer.parseInt(idDelete.getText()));
	}
}
